import React, { Component, ComponentType } from 'react';

import { AppState } from './app-state/app-state.types';

function StateContext<V = AppState>(ContextProvider: ComponentType<{ value: V }>, contextData: V) {
    return function (InnerCom: ComponentType) {
        class WrappedContextComponent extends Component {
            static displayName = `StateContextComponent(${InnerCom?.displayName || InnerCom?.name})`;

            render() {
                return (
                    <ContextProvider value={contextData}>
                        <InnerCom />
                    </ContextProvider>
                );
            }
        }

        return WrappedContextComponent;
    };
}

export { StateContext };
